<?php
require ('./func.req.php');

/*
  -----------------------------------
  ---- SCRIPT D'AUTHENTIFICATION ----
  FujiCraft V3.0
  By Fujido
  Contact : thefujido@gmail.com
  -----------------------------------
 */

session_start(); // On relaye la session
if (@session_is_registered("authentification")) { // v�rification sur la session authentification (la session est elle enregistr�e ?)
// ici les �ventuelles actions en cas de r�ussite de la connexion
}
// GESTION DE LA D�connexion
if (isset($_GET['erreur']) && $_GET['erreur'] == 'logout') { // Test sur les param�tres d'URL qui permettront d'identifier un "contexte" de d�connexion
    $prenom = $_SESSION['prenom']; // On garde le pr�nom en variable pour dire au revoir (soyons polis :-)
    @session_unset("authentification");
    header("Location:login.php?erreur=logout");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title><?php echo $site; ?> | Contact</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="Content-Style-Type" content="text/css" />
        <meta http-equiv="content-language" content="fr,en" />
        <link rel='shortcut icon' type="image/x-icon" href='./images/favicon.ico' />
        <link rel="stylesheet" type="text/css" href="./css/style.css" title="" media="all" />
        <link rel="stylesheet" type="text/css" href="./css/news.css" title="" media="all" />
        <link rel="stylesheet" type="text/css" href="./css/comment.css" title="" media="all" />
        <script type="text/javascript" src="./js/news.js"></script>
    </head>
    <body>
        <div id="block">
            <div id="contentblock">
                <div class="wrapper">
                    <?php
                    show_header();
                    show_menu();
                    show_newsbox();
                    show_userbox();
                    $opt1 = "Rapport de bug";
                    $opt2 = "Question";
                    $opt3 = "Ajout d'une personne sur la whitelist";
                    $opt4 = "Probl&egrave;me sur le serveur";
                    $opt5 = "D&eacute;noncer une personne malveillante";
                    ?>
                    <div class="mainbox">
                        <h2>Contact</h2>
                        <br />
                        <center>
                            <?php
                            if (@session_is_registered("authentification")) { // v�rification sur la session authentification (la session est elle enregistr�e ?)
                                ?>
                                <form action="" method="POST">
                                    <table id="pattern-style-b" summary="Contact">
                                        <thead>
                                            <th colspan="2" scope="col">Contact</th>
                                        </thead>
                                        <tbody>
    <!--                                            <tr>
                                                <td>Pseudo : </td><td><?php echo $_SESSION['login']; ?><input type="hidden" name="pseudo_log" value="<?php $_SESSION['login']; ?>" /></td>
                                            </tr>
                                            <tr>
                                                <td>E-mail : </td><td><?php echo $_SESSION['email']; ?><input type="hidden" name="email_log" value="<?php $_SESSION['email']; ?>" /></td>
                                            </tr>-->
                                            <tr>
                                                <td>Sujet : </td>
                                                <td>
                                                    <select name="sujet_log">
                                                        <option><?php echo $opt1; ?></option>
                                                        <option><?php echo $opt2; ?></option>
                                                        <option><?php echo $opt3; ?></option>
                                                        <option><?php echo $opt4; ?></option>
                                                        <option><?php echo $opt5; ?></option>
                                                    </select>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>Message : </td><td><textarea cols="40" rows="5" name="mess_log"></textarea></td>
                                            </tr>
                                            <tr>
                                                <td>&nbsp;</td><td>&nbsp;</td>
                                            </tr>
                                            <tr>
                                                <td colspan="2"><input type="submit" name="envoyer_log" class="btn" value="Envoyer"/></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </form>
                                <?php
                                if (isset($_POST['envoyer_log'])) {
                                    if (!empty($_POST['sujet_log']) && !empty($_POST['mess_log'])) {
                                        $de = $_SESSION['email'];
                                        $sujet = $_POST['sujet_log'];
                                        $mess = $_POST['mess_log'];

                                        $to = 'info@galaxy-serveur.ch';
                                        $subject = $sujet;
                                        $message = "Pseudo : " . $_SESSION['login'] . "
                                    
Message : 

" . $mess;
                                        $headers = 'From: ' . $de . "\r\n" .
                                                'Reply-To: ' . $de . "\r\n" .
                                                'X-Mailer: PHP/' . phpversion();

                                        if (mail($to, $subject, $message, $headers)) {
                                            ?>
                                            <div id="box" onclick="document.getElementById('box').style.display='none';" class="success-box rounded" title="Fermer la fen&ecirc;tre">
                                                Votre message &agrave; bien &eacute;t&eacute; envoy&eacute;.
                                            </div>
                                            <?php
                                        } else {
                                            ?>
                                            <div id="box" onclick="document.getElementById('box').style.display='none';" class="error-box rounded" title="Fermer la fen&ecirc;tre">
                                                Tout les champs non pas &eacute;t&eacute; remplis.
                                            </div>
                                            <?php
                                        }
                                    }
                                }
                            } else {
                                ?>
                                <form action="" method="POST">
                                    <table id="pattern-style-b" summary="Contact">
                                        <thead>
                                            <th colspan="2" scope="col">Contact</th>
                                        </thead>
                                        <tbody>
                                            <tr>
                                                <td>Pseudo : </td><td><input type="text" name="pseudo" /></td>
                                            </tr>
                                            <tr>
                                                <td>E-mail : </td><td><input type="text" name="email" /></td>
                                            </tr>
                                            <tr>
                                                <td>Sujet : </td>
                                                <td>
                                                    <select name="sujet">
                                                        <option><?php echo $opt1; ?></option>
                                                        <option><?php echo $opt2; ?></option>
                                                        <option><?php echo $opt3; ?></option>
                                                        <option><?php echo $opt4; ?></option>
                                                        <option><?php echo $opt5; ?></option>
                                                    </select>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>Message : </td><td><textarea cols="40" rows="5"  name="mess"></textarea></td>
                                            </tr>
                                            <tr>
                                                <td>&nbsp;</td><td>&nbsp;</td>
                                            </tr>
                                            <tr>
                                                <td colspan="2"><input type="submit" name="envoyer" class="btn" value="Envoyer"/></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </form>
                                <?php
                                if (isset($_POST['envoyer'])) {
                                    if (!empty($_POST['pseudo']) && !empty($_POST['email']) && !empty($_POST['sujet']) && !empty($_POST['mess'])) {

                                        if (preg_match("#^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$#", $_POST['email'])) {


                                            $de = $_POST['email'];
                                            $sujet = $_POST['sujet'];
                                            $mess = $_POST['mess'];

                                            $to = 'info@galaxy-serveur.ch';
                                            $subject = $sujet;
                                            $message = "Pseudo : " . $_POST['pseudo'] . "
                                    
Message : 

" . $mess;
                                            $headers = 'From: ' . $de . "\r\n" .
                                                    'Reply-To: ' . $de . "\r\n" .
                                                    'X-Mailer: PHP/' . phpversion();

                                            if (mail($to, $subject, $message, $headers)) {
                                                ?>
                                                <div id="box" onclick="document.getElementById('box').style.display='none';" class="success-box rounded" title="Fermer la fen&ecirc;tre">
                                                    Votre message &agrave; bien &eacute;t&eacute; envoy&eacute;.
                                                </div>
                                                <?php
                                            } else {
                                                ?>
                                                <div id="box" onclick="document.getElementById('box').style.display='none';" class="error-box rounded" title="Fermer la fen&ecirc;tre">
                                                    Tout les champs non pas &eacute;t&eacute; remplis.
                                                </div>
                                                <?php
                                            }
                                        } else {
                                            ?>
                                            <div id="box" onclick="document.getElementById('box').style.display='none';" class="error-box rounded" title="Fermer la fen&ecirc;tre">
                                                L'email que vous avez entr&eacute; n'est pas valide.
                                            </div>
                                            <?php
                                        }
                                    }
                                }
                            }
                            ?>
                        </center>
                        <br />
                    </div>
                    <?php show_footer(); ?>
                </div>
            </div>
        </div>
    </body>
</html>
